<?php
/**
 *	@author Jacken
 *	
 *	Save user account into database
 */

// Connect to database.
// $mysqli
/*
include_once('db_connect.php');
include_once('User.php');

class SignUp {

	private $connect;
	private $mysqli;

	// Constructor.
	function SignUp() {
		$this->connect = new Connect();
		$this->mysqli = $this->connect->getMysqli();
	}

	/**
	 *	INSERT new USER OBJECT
	 *	
	 * - input is an user object
	 */
	function insert($user) {

		// Get info from User object
		$userName = $user->getUserName();
		$passWord = $user->getPassWord();
		$id = 0;

		try {
			// sql query
			$sqlInsert = "INSERT INTO USER 
						(userName, passWord) 
						VALUES 
						(?, ?)";

			// Prepare query.
			$prInsert = $this->mysqli->prepare($sqlInsert);
			// check
			if($prInsert) {
				// If prepare Statement is true.
				// Bind.
				$prInsert->bind_param('ss', $userName, $passWord);
			} else {
				echo "Prepare failed: (" .$this->mysqli->errno. ") " .$this->mysqli->error;
			}

			// execute sql query
			if(!$prInsert->execute()) {
				echo "Error execute: (". $prInsert->errno. ") " .$prInsert->error;
			}

			// Get the newest id
			$id = $this->mysqli->insert_id;
		} catch (Exception $e) {
			echo $e->getMessage();
		} finally {
			mysqli_close($this->mysqli);
		}
		return $id;
	}
}
*/
?>